<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>blockquote_test.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="local_closure_goog_editor_plugins_blockquote_test.js.html">blockquote_test.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2009 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>goog.provide(&#39;goog.editor.plugins.BlockquoteTest&#39;);
<a name="line16"></a>goog.setTestOnly(&#39;goog.editor.plugins.BlockquoteTest&#39;);
<a name="line17"></a>
<a name="line18"></a>goog.require(&#39;goog.dom&#39;);
<a name="line19"></a>goog.require(&#39;goog.dom.Range&#39;);
<a name="line20"></a>goog.require(&#39;goog.dom.TagName&#39;);
<a name="line21"></a>goog.require(&#39;goog.editor.plugins.Blockquote&#39;);
<a name="line22"></a>goog.require(&#39;goog.testing.editor.FieldMock&#39;);
<a name="line23"></a>goog.require(&#39;goog.testing.editor.TestHelper&#39;);
<a name="line24"></a>goog.require(&#39;goog.testing.jsunit&#39;);
<a name="line25"></a>goog.require(&#39;goog.userAgent&#39;);
<a name="line26"></a>
<a name="line27"></a>var SPLIT = &#39;&lt;span id=&quot;split-point&quot;&gt;&lt;/span&gt;&#39;;
<a name="line28"></a>var root, helper, field, plugin;
<a name="line29"></a>
<a name="line30"></a>function setUp() {
<a name="line31"></a>  root = goog.dom.getElement(&#39;root&#39;);
<a name="line32"></a>  helper = new goog.testing.editor.TestHelper(root);
<a name="line33"></a>  field = new goog.testing.editor.FieldMock();
<a name="line34"></a>
<a name="line35"></a>  helper.setUpEditableElement();
<a name="line36"></a>}
<a name="line37"></a>
<a name="line38"></a>function tearDown() {
<a name="line39"></a>  field.$verify();
<a name="line40"></a>  helper.tearDownEditableElement();
<a name="line41"></a>}
<a name="line42"></a>
<a name="line43"></a>function createPlugin(requireClassname, opt_paragraphMode) {
<a name="line44"></a>  field.queryCommandValue(&#39;+defaultTag&#39;).$anyTimes().$returns(
<a name="line45"></a>      opt_paragraphMode ? goog.dom.TagName.P : undefined);
<a name="line46"></a>
<a name="line47"></a>  plugin = new goog.editor.plugins.Blockquote(requireClassname);
<a name="line48"></a>  plugin.registerFieldObject(field);
<a name="line49"></a>  plugin.enable(field);
<a name="line50"></a>}
<a name="line51"></a>
<a name="line52"></a>function execCommand() {
<a name="line53"></a>  field.$replay();
<a name="line54"></a>
<a name="line55"></a>  // With splitPoint we try to mimic the behavior of EnterHandler&#39;s
<a name="line56"></a>  // deleteCursorSelection_.
<a name="line57"></a>  var splitPoint = goog.dom.getElement(&#39;split-point&#39;);
<a name="line58"></a>  var position = goog.userAgent.IE ?
<a name="line59"></a>      splitPoint : {node: splitPoint.nextSibling, offset: 0};
<a name="line60"></a>  if (!goog.userAgent.IE) {
<a name="line61"></a>    goog.dom.removeNode(splitPoint);
<a name="line62"></a>    goog.dom.Range.createCaret(position.node, 0).select();
<a name="line63"></a>  } else {
<a name="line64"></a>    goog.dom.Range.createCaret(position, 0).select();
<a name="line65"></a>  }
<a name="line66"></a>
<a name="line67"></a>  var result = plugin.execCommand(goog.editor.plugins.Blockquote.SPLIT_COMMAND,
<a name="line68"></a>      position);
<a name="line69"></a>  if (goog.userAgent.IE) {
<a name="line70"></a>    goog.dom.removeNode(splitPoint);
<a name="line71"></a>  }
<a name="line72"></a>
<a name="line73"></a>  return result;
<a name="line74"></a>}
<a name="line75"></a>
<a name="line76"></a>function testSplitBlockquoteDoesNothingWhenNotInBlockquote() {
<a name="line77"></a>  root.innerHTML = &#39;&lt;div&gt;Test&#39; + SPLIT + &#39;ing&lt;/div&gt;&#39;;
<a name="line78"></a>
<a name="line79"></a>  createPlugin(false);
<a name="line80"></a>  assertFalse(execCommand());
<a name="line81"></a>  helper.assertHtmlMatches(&#39;&lt;div&gt;Testing&lt;/div&gt;&#39;);
<a name="line82"></a>}
<a name="line83"></a>
<a name="line84"></a>function testSplitBlockquoteDoesNothingWhenNotInBlockquoteWithClass() {
<a name="line85"></a>  root.innerHTML = &#39;&lt;blockquote&gt;Test&#39; + SPLIT + &#39;ing&lt;/blockquote&gt;&#39;;
<a name="line86"></a>
<a name="line87"></a>  createPlugin(true);
<a name="line88"></a>  assertFalse(execCommand());
<a name="line89"></a>  helper.assertHtmlMatches(&#39;&lt;blockquote&gt;Testing&lt;/blockquote&gt;&#39;);
<a name="line90"></a>}
<a name="line91"></a>
<a name="line92"></a>function testSplitBlockquoteInBlockquoteWithoutClass() {
<a name="line93"></a>  root.innerHTML = &#39;&lt;blockquote&gt;Test&#39; + SPLIT + &#39;ing&lt;/blockquote&gt;&#39;;
<a name="line94"></a>
<a name="line95"></a>  createPlugin(false);
<a name="line96"></a>  assertTrue(execCommand());
<a name="line97"></a>  helper.assertHtmlMatches(
<a name="line98"></a>      &#39;&lt;blockquote&gt;Test&lt;/blockquote&gt;&#39; +
<a name="line99"></a>      &#39;&lt;div&gt;[[!IE]]&amp;nbsp;&lt;/div&gt;&#39; +
<a name="line100"></a>      &#39;&lt;blockquote&gt;ing&lt;/blockquote&gt;&#39;);
<a name="line101"></a>}
<a name="line102"></a>
<a name="line103"></a>function testSplitBlockquoteInBlockquoteWithoutClassInParagraphMode() {
<a name="line104"></a>  root.innerHTML = &#39;&lt;blockquote&gt;Test&#39; + SPLIT + &#39;ing&lt;/blockquote&gt;&#39;;
<a name="line105"></a>
<a name="line106"></a>  createPlugin(false, true);
<a name="line107"></a>  assertTrue(execCommand());
<a name="line108"></a>  helper.assertHtmlMatches(
<a name="line109"></a>      &#39;&lt;blockquote&gt;Test&lt;/blockquote&gt;&#39; +
<a name="line110"></a>      &#39;&lt;p&gt;[[!IE]]&amp;nbsp;&lt;/p&gt;&#39; +
<a name="line111"></a>      &#39;&lt;blockquote&gt;ing&lt;/blockquote&gt;&#39;);
<a name="line112"></a>}
<a name="line113"></a>
<a name="line114"></a>function testSplitBlockquoteInBlockquoteWithClass() {
<a name="line115"></a>  root.innerHTML =
<a name="line116"></a>      &#39;&lt;blockquote class=&quot;tr_bq&quot;&gt;Test&#39; + SPLIT + &#39;ing&lt;/blockquote&gt;&#39;;
<a name="line117"></a>
<a name="line118"></a>  createPlugin(true);
<a name="line119"></a>  assertTrue(execCommand());
<a name="line120"></a>  helper.assertHtmlMatches(
<a name="line121"></a>      &#39;&lt;blockquote class=&quot;tr_bq&quot;&gt;Test&lt;/blockquote&gt;&#39; +
<a name="line122"></a>      &#39;&lt;div&gt;[[!IE]]&amp;nbsp;&lt;/div&gt;&#39; +
<a name="line123"></a>      &#39;&lt;blockquote class=&quot;tr_bq&quot;&gt;ing&lt;/blockquote&gt;&#39;);
<a name="line124"></a>}
<a name="line125"></a>
<a name="line126"></a>function testSplitBlockquoteInBlockquoteWithClassInParagraphMode() {
<a name="line127"></a>  root.innerHTML =
<a name="line128"></a>      &#39;&lt;blockquote class=&quot;tr_bq&quot;&gt;Test&#39; + SPLIT + &#39;ing&lt;/blockquote&gt;&#39;;
<a name="line129"></a>
<a name="line130"></a>  createPlugin(true, true);
<a name="line131"></a>  assertTrue(execCommand());
<a name="line132"></a>  helper.assertHtmlMatches(
<a name="line133"></a>      &#39;&lt;blockquote class=&quot;tr_bq&quot;&gt;Test&lt;/blockquote&gt;&#39; +
<a name="line134"></a>      &#39;&lt;p&gt;[[!IE]]&amp;nbsp;&lt;/p&gt;&#39; +
<a name="line135"></a>      &#39;&lt;blockquote class=&quot;tr_bq&quot;&gt;ing&lt;/blockquote&gt;&#39;);
<a name="line136"></a>}
<a name="line137"></a>
<a name="line138"></a>function testIsSplittableBlockquoteWhenRequiresClassNameToSplit() {
<a name="line139"></a>  createPlugin(true);
<a name="line140"></a>
<a name="line141"></a>  var blockquoteWithClassName = goog.dom.createDom(&#39;blockquote&#39;, &#39;tr_bq&#39;);
<a name="line142"></a>  assertTrue(&#39;blockquote should be detected as splittable&#39;,
<a name="line143"></a>      plugin.isSplittableBlockquote(blockquoteWithClassName));
<a name="line144"></a>
<a name="line145"></a>  var blockquoteWithoutClassName = goog.dom.createDom(&#39;blockquote&#39;, &#39;foo&#39;);
<a name="line146"></a>  assertFalse(&#39;blockquote should not be detected as splittable&#39;,
<a name="line147"></a>      plugin.isSplittableBlockquote(blockquoteWithoutClassName));
<a name="line148"></a>
<a name="line149"></a>  var nonBlockquote = goog.dom.createDom(&#39;span&#39;, &#39;tr_bq&#39;);
<a name="line150"></a>  assertFalse(&#39;element should not be detected as splittable&#39;,
<a name="line151"></a>      plugin.isSplittableBlockquote(nonBlockquote));
<a name="line152"></a>}
<a name="line153"></a>
<a name="line154"></a>function testIsSplittableBlockquoteWhenNotRequiresClassNameToSplit() {
<a name="line155"></a>  createPlugin(false);
<a name="line156"></a>
<a name="line157"></a>  var blockquoteWithClassName = goog.dom.createDom(&#39;blockquote&#39;, &#39;tr_bq&#39;);
<a name="line158"></a>  assertTrue(&#39;blockquote should be detected as splittable&#39;,
<a name="line159"></a>      plugin.isSplittableBlockquote(blockquoteWithClassName));
<a name="line160"></a>
<a name="line161"></a>  var blockquoteWithoutClassName = goog.dom.createDom(&#39;blockquote&#39;, &#39;foo&#39;);
<a name="line162"></a>  assertTrue(&#39;blockquote should be detected as splittable&#39;,
<a name="line163"></a>      plugin.isSplittableBlockquote(blockquoteWithoutClassName));
<a name="line164"></a>
<a name="line165"></a>  var nonBlockquote = goog.dom.createDom(&#39;span&#39;, &#39;tr_bq&#39;);
<a name="line166"></a>  assertFalse(&#39;element should not be detected as splittable&#39;,
<a name="line167"></a>      plugin.isSplittableBlockquote(nonBlockquote));
<a name="line168"></a>}
<a name="line169"></a>
<a name="line170"></a>function testIsSetupBlockquote() {
<a name="line171"></a>  createPlugin(false);
<a name="line172"></a>
<a name="line173"></a>  var blockquoteWithClassName = goog.dom.createDom(&#39;blockquote&#39;, &#39;tr_bq&#39;);
<a name="line174"></a>  assertTrue(&#39;blockquote should be detected as setup&#39;,
<a name="line175"></a>      plugin.isSetupBlockquote(blockquoteWithClassName));
<a name="line176"></a>
<a name="line177"></a>  var blockquoteWithoutClassName = goog.dom.createDom(&#39;blockquote&#39;, &#39;foo&#39;);
<a name="line178"></a>  assertFalse(&#39;blockquote should not be detected as setup&#39;,
<a name="line179"></a>      plugin.isSetupBlockquote(blockquoteWithoutClassName));
<a name="line180"></a>
<a name="line181"></a>  var nonBlockquote = goog.dom.createDom(&#39;span&#39;, &#39;tr_bq&#39;);
<a name="line182"></a>  assertFalse(&#39;element should not be detected as setup&#39;,
<a name="line183"></a>      plugin.isSetupBlockquote(nonBlockquote));
<a name="line184"></a>}
<a name="line185"></a>
<a name="line186"></a>function testIsUnsetupBlockquote() {
<a name="line187"></a>  createPlugin(false);
<a name="line188"></a>
<a name="line189"></a>  var blockquoteWithClassName = goog.dom.createDom(&#39;blockquote&#39;, &#39;tr_bq&#39;);
<a name="line190"></a>  assertFalse(&#39;blockquote should not be detected as unsetup&#39;,
<a name="line191"></a>      plugin.isUnsetupBlockquote(blockquoteWithClassName));
<a name="line192"></a>
<a name="line193"></a>  var blockquoteWithoutClassName = goog.dom.createDom(&#39;blockquote&#39;, &#39;foo&#39;);
<a name="line194"></a>  assertTrue(&#39;blockquote should be detected as unsetup&#39;,
<a name="line195"></a>      plugin.isUnsetupBlockquote(blockquoteWithoutClassName));
<a name="line196"></a>
<a name="line197"></a>  var nonBlockquote = goog.dom.createDom(&#39;span&#39;, &#39;tr_bq&#39;);
<a name="line198"></a>  assertFalse(&#39;element should not be detected as unsetup&#39;,
<a name="line199"></a>      plugin.isUnsetupBlockquote(nonBlockquote));
<a name="line200"></a>}
</pre>


</body>
</html>
